import { api } from '../boot/axios';
import { searchDepotType } from './type'

function url(s: string) {
  if (s == '') {
    return ['/api/depot', ''].join('/');
  }
  return ['/api/depot', s.replace('/', ''), ''].join('/');
}

export async function getDepotParts(car: string) {
  return api({
    url: url('get_parts_from_car'),
    method: 'post',
    data: {
      car,
    },
  });
}
export async function getDepotPartsBySerial(serial_no: string, stock_code: string) {
  return api({
    url: url('get_parts_from_parent'),
    method: 'post',
    data: {
      serial_no,
      stock_code
    },
  });
}

export async function depotFitment(
  parent_stock_code: string,
  parent_serial_no: string,
  new_car: string
) {
  return api({
    url: url('fitment'),
    method: 'post',
    data: {
      parent_stock_code:parent_stock_code.toUpperCase(),
      parent_serial_no,
      new_car,
    },
  });
}

/**
 * 查询 depot 数据
 * @param stock_code 
 * @param serial_no 
 * @returns 
 */
export const selectDepotList = (data:searchDepotType)=> {
  const { stock_code='', serial_no='', page_size='10', page_num='1' } = data
  return api({
    url: url('search_parts_fitment_paging')+`?page_size=${page_size}&page_num=${page_num}`,
    method: 'post',
    data: {
      stock_code,
      serial_no,
    },
  });
}
